package com.fjec.devops.controller;

import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.common.annotation.OpeLog;
import com.fjec.common.okhttp.OkHttp;
import com.fjec.common.protocol.JsonResult;
import com.fjec.common.util.DateUtil;
import com.fjec.devops.entity.InfoCooperator;
import com.google.j2objc.annotations.AutoreleasePool;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fjec.devops.service.IInfoCooperatorService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Blob;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2020-10-26
 */
@RestController
@RequestMapping("/")
public class InfoCooperatorController {

    @Resource
    private IInfoCooperatorService service;

    @OpeLog(desc = "增加或修改合伙人信息")
    @PostMapping("/y/cooperator/saveOrUpdate")
    public JsonResult saveOrUpdate(InfoCooperator infoCooperator) {
        service.saveOrUpdateCooperator(infoCooperator);
        return JsonResult.SUCCESS;
    }


    @GetMapping("/y/cooperator/getList")
    public JsonResult getList(Page page) {
        page = service.page(page, new QueryWrapper<InfoCooperator>()
                .orderByAsc("CreateTime"));

        return JsonResult.success()
                .data(page.getRecords())
                .total(page.getTotal())
                .build();
    }

    /**
     *
     * @param id
     * @return
     */
    @GetMapping("/y/cooperator/getById")
    public JsonResult getById(Long id) {
        InfoCooperator infoCooperator = service.getById(id);
        return JsonResult.success().data(infoCooperator).build();
    }

//    @GetMapping("/n/cooperator/get/barcode")
//    public void downloadBarcode(Long id, HttpServletResponse response) throws Exception {
//        service.downloadBarcode(id, response);
//    }
}
